
float sdfSphereDis2D(float2 p, float r)
{
    float retV = length(p) - r;
    return retV;
}

float sdfSphereDis(float3 p, float r)
{
    float retV = length(p) - r;
    return retV;
}
float sdEquilateralTriangleDis2D(float2 p, float r)
{
     float k = sqrt(3.0);
    p.x = abs(p.x) - r;
    p.y = p.y + r/k;
    if( p.x+k*p.y>0.0 )
        p = float2(p.x-k*p.y,-k*p.x-p.y)/2.0;
    p.x -= clamp( p.x, -2.0*r, 0.0 );
    return -length(p)*sign(p.y);
}

float sdBoxDis2D( float2 p, float2 b )
{
    float2 d = abs(p)-b;
    return length(max(d,0.0)) + min(max(d.x,d.y),0.0);
}

float SmoothUnion(float dis1, float dis2, float blendIntense)
{
    float h = clamp(0.5 + 0.5 * (dis2-dis1)/blendIntense, 0.0, 1.0);
    return lerp(dis2, dis1, h) - blendIntense * h * (1.0-h);
}